//
//  WYSelectYearView.m
//  Boss
//
//  Created by admin on 2018/7/11.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYSelectYearView.h"
@interface WYSelectYearView()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (nonatomic,strong)UIView *toolView;
@property (nonatomic,strong)UIPickerView *pickerView;

@property (nonatomic,strong)NSArray *dataArray;

@end



@implementation WYSelectYearView
-(NSArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = @[@"2018"];
    }
    
    return _dataArray;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews
{
    self.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5];
    
    
    
    UIView *toolView = [[UIView alloc]init];
    self.toolView = toolView;
    [self addSubview:toolView];
    toolView.backgroundColor = [UIColor whiteColor];
    
    [toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(44);
        make.bottom.mas_equalTo(-215);
    }];
    UIButton *cancelBtn = [[UIButton alloc]init];
    [toolView addSubview:cancelBtn];
    
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(toolView);
    }];
    
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
    [cancelBtn setTitleColor:kColor333333 forState:(UIControlStateNormal)];
    [cancelBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    UIButton *surebtn = [[UIButton alloc]init];
    [toolView addSubview:surebtn];
    
    [surebtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(toolView);
    }];
    
    [surebtn setTitle:@"确定" forState:(UIControlStateNormal)];
    [surebtn setTitleColor:kColorMainColor forState:(UIControlStateNormal)];
    surebtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [surebtn addTarget:self action:@selector(clickSureAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    UILabel *titleLabel =[[UILabel alloc]init];
    [toolView addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(toolView);
    }];
    titleLabel.font = [UIFont systemFontOfSize:14];
    titleLabel.text  = @"选择年份";
    titleLabel.textColor = kColor999999;
    
    self.pickerView = [[UIPickerView alloc]init];
    [self addSubview:self.pickerView];
    self.pickerView.backgroundColor = [UIColor whiteColor];
    [self.pickerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(215);
    }];
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    
    
    
    
    
    
}

// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.dataArray.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.dataArray[row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.selectYear  = self.dataArray[row];
}



-(void)show
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
}
-(void)hide
{
    [self removeFromSuperview];
}
-(void)clickSureAction
{
    if (self.complte) {
        self.complte(self.selectYear);
    }
    [self hide];
    
    
    
}

@end
